package com.cms.controller.front;

import com.cms.domain.Feedback;
import com.cms.entity.Guestbook;
import com.cms.entity.Site;
import com.cms.service.GuestbookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.HashMap;
/**
 * Controller - 留言
 *
 *
 *
 */
@Slf4j
@Controller("frontGuestbookController")
@RequestMapping("/guestbook")
public class GuestbookController extends BaseController {

    @Autowired
    private GuestbookService guestbookService;

    /**
     * 保存
     */
    @ResponseBody
    @RequestMapping("/save")
    public Feedback save(Guestbook guestbook){
        log.info("留言保存...");
        Site currentSite = getCurrentSite();
        guestbook.setStatus(0);
        guestbook.setCreateDate(LocalDateTime.now());
        guestbook.setUpdateDate(LocalDateTime.now());
        guestbook.setSiteId(currentSite.getId());
        guestbookService.save(guestbook);
        return Feedback.success(new HashMap<>());
    }
}
